<?php

//C:\wamp\bin\php\php5.4.12\php.exe -f C:\phproot\rush\trunk\Cli\jdtop_batch.php
set_time_limit(0);

define('ROOT_PATH', str_replace('Cli/'.basename(__FILE__), '', str_replace('\\', '/', __FILE__)));

require_once(ROOT_PATH."Cls/common.php");
require_once(ROOT_PATH."Cls/db.php");
require_once(ROOT_PATH."Cls/Snoopy.class.php");
require_once(ROOT_PATH."Cls/lib_jd.php");

//初始化
$db = new DB();

//读取需要抓取的列表
$ranks = $db->get_all("SELECT * FROM jd_rank WHERE item_id !='' AND url != '' AND disabled = 0 ORDER BY id DESC");

foreach($ranks as $i => $r){

    //排名
    $id         = $r['id'];
    $item_id    = $r['item_id'];
    $url        = $r['url'];
    $top        = get_item_top($r);
    $dateline   = time();

    $db->query("UPDATE jd_rank SET rank = {$top},dateline = '$dateline' WHERE id = {$id}");

    //添加当天的记录
    add_by_created($id,$top);

    //休息
    sleep_rand();


    echo $R=<<<R
id      = $id
item_id = $item_id
url     = $url
top     = $top

R;
}
exit;
